fwrite函数的用法示例

您所在的位置:网站首页 verilog $fwrite参数 fwrite函数的用法示例

fwrite函数的用法示例

2024-02-12 11:43| 来源: 网络整理| 查看: 265

fwrite函数的用法示例

C中的fwrite()函数 (fwrite() function in C)

Prototype:

原型:

size_t fwrite(void *buffer, size_t length, size_t count, FILE *filename);

Parameters:

参数:

void *buffer, size_t length, size_t count, FILE *filename

Return type: size_t

返回类型: size_t

Use of function:

使用功能:

The prototype of the function fwrite() is:

函数fwrite()的原型为:

size_t fwrite(void *buffer, size_t length, size_t count, FILE *filename);

In the file handling, through the fwrite() function we write count number of objects of size length to the input stream filename from the array named as buffer. Its returns the number of objects that it will write to the file. If fewer number of objects will be written or EOF is encountered then it will throw an error.

在文件处理中,通过fwrite()函数,我们将大小为长度的对象的计数写入名为缓冲区的数组的输入流文件名中。 它返回将写入文件的对象数。 如果要写入的对象数量较少或遇到EOF ,则它将引发错误。

C语言中的fwrite()示例 (fwrite() example in C) #include #include int main(){ FILE *f; //initialize the arr1 with values int arr1[5]={1,2,3,4,5}; int arr2[5]; int i=0; //open the file for write operation if((f=fopen("includehelp.txt","w"))==NULL){ //if the file does not exist print the string printf("Cannot open the file..."); exit(1); } //write the values on the file if((fwrite(arr1,sizeof(int),5,f))!=5){ printf("File write error....\n"); } //close the file fclose(f); //open the file for read operation if((f=fopen("includehelp.txt","r"))==NULL){ //if the file does not exist print the string printf("Cannot open the file..."); exit(1); } //read the values from the file and store it into the array if((fread(arr2,sizeof(int),5,f))!=5){ printf("File write error....\n"); } fclose(f); for(i=0;i


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3